package main

import (
	"flag"
	"github.com/golang/glog"
	"logs/logger"
	"logs/logs"
	"logs/test"
	"time"
)

func main() {
	//testLogger()
	testLogs()
	//testGlog()
}

func testLogs() {
	// logs.Init(true, true, "/Volumes/KINGSTON/Study/goland/go-logs/logs/test.txt")
	logs.Init(&logs.Config{
		Filename: "test.log",
		Level:    logs.LevelDebug,
		Console:  true,
		Rotate:   true,
		Daily:    true,
		MaxDays:  3,
		Separate: []logs.Separate{logs.SeparateError, logs.SeparateDebug},
	})
	for {
		time.Sleep(time.Millisecond * 20)
		logs.Debug("debug....")
		logs.Info("info....")
		logs.ErrorWithStack(test.TT())
		logs.ErrorWithStack(test.TT(), 3)
		logs.Warning("warning....")
		logs.Error("error...")
		logs.Critical("Critical")
		logs.Emergency("我是Em..")
	}
}

func testGlog() {

	// 运行时参数如:
	// go run main.go -log_dir=log -alsologtostderr
	// 注: log_dir不会自动创建
	// 当单个日志文件达到一定大小时，glog 将会有 rotate 的动作：即关闭已经满量的文件，新建日志文件。

	flag.Parse()
	defer glog.Flush()

	glog.Info("This is info message")
	glog.Infof("This is info message: %v", 12345)
	glog.InfoDepth(1, "This is info message", 12345)

	glog.Warning("This is warning message")
	glog.Warningf("This is warning message: %v", 12345)
	glog.WarningDepth(1, "This is warning message", 12345)

	glog.Error("This is error message")
	glog.Errorf("This is error message: %v", 12345)
	glog.ErrorDepth(1, "This is error message", 12345)

	glog.Fatal("This is fatal message")
	// glog.Fatalf("This is fatal message: %v", 12345)
	// glog.FatalDepth(1, "This is fatal message", 12345)

}

func testLogger() {
	logger.Init(true, true, "test.log")
	logger.Debug("debug....")
	logger.Error("error...")
	logger.ErrorWithStack(test.TT())
	logger.ErrorWithStack(test.TT(), 3)
	logger.Panic("panic")
}
